 <extend name="Base/common" />
 
 <block name="style">
 	<link rel="stylesheet" href="__CSS__/User/select.css" />
 </block>
 
<block name="body">
	<div class="text-align-center">
		<h2 id="title">选择你擅长的</h2>
	</div>
	<div class="select">
		<div class="row" id="row">
			<input name="uid" id="uid" value="{$uid}" hidden="hidden"/>
			<foreach name='userimg' item='v'>
	            <div class="col-xs-6">
	            	<input value="{$v.titlename}" name="titlename" id="titlename" hidden="hidden"/>
					<div class="instrument-div" data-id="{$v.id}" onclick="select(this)">
						<img src="{$v.imgurl}" />
					</div>
				</div>
            </foreach>
		</div>
	</div>
	<div class="text-align-center">
		<button class="btn btn-default" id="reload">换一批</button>
		<button class="btn btn-primary" id="submit">完成</button>
	</div>
</block>

<block name="script">
	<script>
		var p = 1;
		//换一批按钮
		$('#reload').click(function(){
			$.post("{:U('User/reload_userimg')}",{p:p},function(res){
				$('#row').html(res.html);
				p = res.p;
			});
		});
		var slectid = null;//如果没选将无法完成
		//选择效果
		function select(o){
			slectid = $(o).attr('data-id');
			$(".instrument-div").removeClass('active');
			$(o).addClass('active');
		}
		var titlename = $('#titlename').val();
		var uid = $('#uid').val();
		//完成按钮提交
		$('#submit').click(function(){
			if(slectid){
				$.post("{:U('User/select')}",{id:slectid,titlename:titlename,uid:uid},function(res){
						if(res.issave){
							if(res.aid){
								location.href="__ROOT__/Activity/act_detail/id/"+res.aid+"/shareaid/"+res.aid+"/isshare/"+1;
							}else{
								location.href="__ROOT__/User/myset";
							}
						}
				});
			}else{
				$('#title').css('color','red');
			}
		});
	</script>
</block>